﻿using System;
using System.Collections.Generic;
using System.Text;
using SwinGame;

namespace SurvivalNN.src
{
    class EntityModel : IEntitySubModel, IEntityModel
    {
        const float SPEED = 100.0f;

        public void Update(float dt)
        {
            Hunger -= HungerRate * dt;
            Warmth -= WarmthRate * dt;
        }

        /////////////
        //Accessors//
        /////////////

        ///////////////
        //Hunger rate//
        ///////////////
        float _hungerRate = 0.4f;
        public float HungerRate { set { _hungerRate = value; } get { return _hungerRate; } }

        ///////////////
        //Warmth rate//
        ///////////////
        float _warmthRate = 0.4f;
        public float WarmthRate { set { _warmthRate = value; } get { return _warmthRate; } }

        ////////////
        //Position//
        ////////////
        Vector _position = new Vector();
        public Vector Position
        {
            get { return _position; }
            set 
            {
                if (_position != value)
                {
                    //Console.WriteLine("X = " + Position.X );
                    PositionChangeHandler(this, new PositionChangeEvent(_position, value));
                    _position = value;
                }
            }
        }

        //////////
        //Hunger//  Hunger level. Decreasing levels create status effects
        //////////  When level reaches 0, Entity Dies

        float _hunger = 100;
        public float Hunger
        {
            get { return _hunger; }
            set
            {
                if (_hunger != value)
                {
                    Console.WriteLine("Hunger = " + Hunger);
                    //StatusChangeHandler(this, new EntityStatusChange(EntityStatusType.ENTITY_HUNGER,_hunger, value));
                    _hunger = value;
                }
            }
        }

        //////////
        //Warmth//  Warmth level. Decreasing levels create status effects
        //////////  When level reaches 0, Entity Dies
        float _warmth = 100;
        public float Warmth
        {
            get { return _warmth; }
            set
            {
                if (_warmth != value)
                {
                    //StatusChangeHandler(this, new EntityStatusChange(EntityStatusType.ENTITY_WARMTH, _warmth, value));
                    _warmth = value;
                }
            }
        }


        //////////////////
        //Event Handlers// 
        //////////////////
        public event EventHandler<PositionChangeEvent> PositionChangeHandler;
        public event EventHandler<EntityStatusChange> StatusChangeHandler;


        ////////////////////////
        //Controller responses// 
        ////////////////////////
        public void MovePositionResponse(object o, MovePropEventArgs eventargs)
        {
            if (eventargs._isRelative)
            {
                Position = new Vector { X = Position.X + eventargs._v.X*SPEED, Y = Position.Y + eventargs._v.Y*SPEED };
            }
            else
            {
                Position = eventargs._v;
            }
        }
        //public void MoveEventResponse(object sender, 


    }
}
